<template>
  <div class="mobile-cont">		
    <div class="banner" >
      <!-- <img src="@assets/image/2024.png" class="img-2024" /> -->
       <img :src="store.index.background_cover"/>   
    </div>

		<div>
			<div class="home-box">
				<img v-if="store.status === 0" class="home-box-title-text" src="@assets/image/home-box-text.png" />
				<img v-if="store.status === 1" class="home-box-title-text" src="@assets/image/home-box-text2.png" />
				<img v-if="store.status === 2" class="home-box-title-text" src="@assets/image/home-box-text3.png" />
				<div class="countdown-sec" v-if="store.status === 0">
					<Countdown :endTime="endTime" />
				</div>
				<!-- 进行中/已结束 -->
				<div>
					<div class="ing-text" v-if="store.status === 1">选择直播平台</div>
					<div class="ing-text" v-if="store.status === 0">扫码了解详情</div>
					<div class="platfrom-group">
						<img v-for="(item, index) in store.index.platform" :src="item.icon"	@click="qrcode = item.qrcode" :key="index"/>
					</div>
					<div class="finish-text" v-show="store.status == 2">预约活动已结束</div>
				</div>
				<div class="home-box-title-sec">
					<img class="QR-code" :src="qrcode" @click="scanQrcode([qrcode],qrcode);" />
				</div>
			</div>

			<div class="users-number">
				<img src="@assets/image/right.png" />
				<div>
					已有<span class="number">{{ store.index.join_virtually || 0}}</span>AI梦想创作者申请入场券
				</div>
				<img src="@assets/image/right.png" />
			</div>
			<my-swiper :list="store.index.persion" style="height: 200px" />
		
			<div class="btn">
				<img @click="show = true" src="@assets/image/finish.png" v-if="!store.lock" />
				<img src="@assets/image/finish-d.png" v-if="store.lock" />
			</div>
		</div>
  </div>
  <Dialog v-if="show" @close="close" />
</template>

<script setup>
import Countdown from "../components/Countdown.vue";
import Dialog from "../components/Dialog.vue";
import mySwiper from "../components/Swiper.vue";
import { ref, onMounted } from "vue";
import { getwxConfig, previewImage } from "@/utils/index";
import { useMobileStore } from "@/api/store";

const store = useMobileStore();
const qrcode = ref(null);
const init = async () => {
  await store.init;
  qrcode.value = store.index.reservation_qrcode;
  await store.getTopFiveUsers;
};

const show = ref(false);
const close = (val) => {
  show.value = val;
};

const wxInit = () => {
  // const url = 'https://chunwan.waytoagi.com';
  const url = window.location.href.split("#")[0];
  return store.share(url).then((res) => {
    getwxConfig(url, res);
  });
};

const scanQrcode = (url, index) => {
  previewImage(url, index)
}

// 倒计时逻辑
const endTime = ref("2025-01-29 18:00:00");
const checkStatus = () => {
  const currentTime = new Date();
  const inProgressTime = new Date('2025-01-29 20:00:00');

  if (currentTime > inProgressTime) {
    store.status = 2; // 已结束
  } else if (currentTime > endTime.value) {
    store.status = 1; // 进行中
  } else {
    store.status = 0; // 倒计时
  }
};

onMounted(() => {
  checkStatus()
  init();
  // wxInit();
  //一般情况下，这样就可以自动播放了，但是一些奇葩iPhone机不可以
  // document.getElementById("car_audio").play();
  //必须在微信Weixin JSAPI的WeixinJSBridgeReady才能生效
  // document.addEventListener(
  //   "WeixinJSBridgeReady",
  //   function () {
  //     document.getElementById("car_audio").load();
  //     document.getElementById("car_audio").pause();
  //     document.getElementById("car_audio").play();
  //     document.getElementById("video").play();
  //   },
  //   false
  // );
  // document.addEventListener(
  //   "touchstart",
  //   function () {
  //     var video = document.getElementById("car_audio");
  //     video.play();
  //   },
  //   false
  // );
});
</script>

<style lang="less" scoped>
.mobile-cont {
  // font-family: MyCustomFont;
  background-image: url("@assets/image/home-bg.png");
  background-size: 100vw auto;
  background-attachment: scroll;
  background-repeat: no-repeat;
  background-position:top left;
  position: relative;
  width: 100vw;
  height: 100vh; 
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  text-align: center;

  .img-2024 {
		display: block;
    width: 45%;
    padding-top: 40px;
		margin-left: auto;
		margin-right: auto;
  }
	.banner {
		// background: url('@/assets/image/poster.jpg') no-repeat;
    // background-size: cover;
    height: 442px;
    img {
      width: 100%;
      height: 100%;
    }
	}
  .home-box {
    // margin-top: 25rem;
    // height: 470px;
    background-image: url('@assets/image/light.png'),url("@assets/image/box.png");
    background-size:  40px auto, 100vw 100%;
    background-repeat: no-repeat;
		padding-bottom: 30px;
		background-position: top 40px left, center;
    // position: absolute;
    .countdown-sec {
      width: 73%;
      margin: 0 auto;
      margin-top: 10px;
    }
    .ing-text {
      color: #fff8c5;
      font-size: 16px;
      margin-bottom: 10px;
      margin-top: 10px;
    }
    .platfrom-group {
      display: flex;
      gap: 0.625rem;
      justify-content: center;
			img {
				width: 2.5rem;
				height: 2.5rem;
			}
    }
    .finish-text {
      background-color: #c8c8c8;
      color: #888;
      text-align: center;
      padding: 0.5625rem 0;
      width: 53%;
      margin: 0.375rem auto -3.9375rem auto;
      position: relative;
      &::before {
        content: "";
        width: 0;
        height: 0;
        left: -20px;
        top: 0;
        position: absolute;
        border-right: 10px solid #c8c8c8;
        border-left: 10px solid transparent;
        border-bottom: 20px solid transparent;
        border-top: 20px solid transparent;
      }
      &::after {
        content: "";
        width: 0;
        height: 0;
        right: -20px;
        top: 0;
        position: absolute;
        border-right: 0.625rem solid transparent;
        border-left: 0.625rem solid #c8c8c8;
        border-bottom: 20px solid transparent;
        border-top: 20px solid transparent;
      }
    }
    .home-box-title-sec {
			background: url('@assets/image/home-box-title.png') no-repeat;
			background-size: 75% 10.125rem;
			background-position: center;
			margin-bottom: 1.3125rem;
    }
    .home-box-title-text {
      margin-top: 2.8125rem;
      width: 60%;
    }
    .QR-code {
      width: 33%;
      margin-left: auto;
			margin-right: auto;
			margin-top: 5rem;
      padding: 5px;
      background-color: #5c0902;
    }
  }
  .users-number {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.5rem;
    color: #ffb778;
    img {
      display: inline-block;
      width: 60px;
      height: 20px;
      &:first-child {
        transform: rotate(180deg);
      }
    }
    .number {
      color: #f7dfb4;
      font-size: 1.75rem;
      font-weight: bold;
      margin-left: 5px;
      margin-right: 5px;
    }
  }
  .btn {
    height: 38px;
    width: 148px;
		margin-left: auto;
		margin-right: auto;
    // margin-top: 30px;
    margin-bottom: 30px;
    // padding-bottom: 60px;
    // position: absolute;
    // top: 150vh;
    img {
      width: inherit;
      cursor: pointer;
    }
  }
}
</style>
